# -*- coding: utf-8 -*-
"""
双色球历史开奖数据爬虫
使用极速数据API抓取双色球开奖数据
"""

from typing import List, Dict, Optional
from loguru import logger

from .jisu_spider import JisuLotterySpider


class SSQSpider(JisuLotterySpider):
    """双色球爬虫 - 基于极速数据API"""
    
    def __init__(self):
        super().__init__('ssq')
    
    def validate_numbers(self, numbers: str) -> bool:
        """验证双色球号码格式
        
        Args:
            numbers: 号码字符串，格式如 "01,02,03,04,05,06,07"
            
        Returns:
            是否有效
        """
        try:
            parts = numbers.split(',')
            if len(parts) != 7:  # 6红球+1蓝球
                return False
            
            # 验证红球（1-33）
            red_balls = [int(x) for x in parts[:6]]
            if not all(1 <= x <= 33 for x in red_balls):
                return False
            
            # 验证蓝球（1-16）
            blue_ball = int(parts[6])
            if not (1 <= blue_ball <= 16):
                return False
            
            return True
            
        except (ValueError, IndexError):
            return False


if __name__ == '__main__':
    # 测试代码
    from loguru import logger
    logger.add("../logs/ssq_spider.log", rotation="1 day", retention="30 days")
    
    spider = SSQSpider()
    result = spider.run()
    logger.info(f"爬取结果: {result}")